package com.msb.service;


import com.msb.pojo.Person;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.util.List;

/**
 * @author sunpeng
 * @Date 2021-07-21 16:20
 */
@Service
public class PersonService {

    public List<Person> show(){

        try {
            ZooKeeper zookeeper = new ZooKeeper("10.1.20.89:2181", 10000, null);
            byte[] result = zookeeper.getData("/rpc/provider", false, null);

            MyPersonService myPersonService =  (MyPersonService)Naming.lookup(new String(result));
            List<Person> personList = myPersonService.findAll();
            System.out.println(personList);

            return personList;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (KeeperException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (NotBoundException e) {
            e.printStackTrace();
        }

        return null;
    }
}
